<template>
    <div class="banner">
        <img v-for="(v, i) in bannerlist" :key="i" :src="baseUr + v.imageUrl" alt="" v-show="n == i">
    </div>
</template>

<script>
import service from "../../api/index";
import {stringBaseURL} from "../../api/urlconfig";
export default {
    data() {
        return {
            n: 0,//初始化
            bannerlist: [],
            baseUr:stringBaseURL()
            // bannerlist:[
            //     require("@/assets/images/banner-1.jpg"),
            //     require("@/assets/images/banner-2.jpg"),
            //     require("@/assets/images/banner-3.jpg"),
            //     require("@/assets/images/banner-4.jpg"),
            //     require("@/assets/images/banner-5.jpg"),
            //     require("@/assets/images/banner-6.jpg"),
            // ]
        }
    },
    mounted() {
        this.autoimages();
        this.play()
    },
    methods: {
        autoPlay() {
            this.n++;
            if (this.n == this.bannerlist.length) {
                this.n = 0;
            }
        },
        play() {
            setInterval(this.autoPlay, 2000)  //时间器，
        },
        autoimages() {

            service.get("api/PlatformIndex/GetRotationChart").then(reponse => {
                let { success, message, data } = reponse.data;
                if (success) { 
                    this.bannerlist = data;
                }
            });
        }

    }
}
</script>




